package com.jt.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jt.mapper.UserMapper;
import com.jt.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Service
public class UserServiceImpl implements UserService{

    @Autowired
    private UserMapper userMapper;


    @Override
    public List<User> findAll(){

        return userMapper.selectList(null);
    }


    public User getUserById(Integer id){

        return userMapper.selectById(id);
    }

    public List<User> getUserByUS(User user){

        //根据对象不为null的属性充当where条件
        QueryWrapper queryWrapper = new QueryWrapper(user);

        return userMapper.selectList(queryWrapper);
    }

    public List<User> getUserByName(String name){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.like("name",name);
        //queryWrapper.likeLeft("name",name);
        return userMapper.selectList(queryWrapper);
    }

    @Override
    public void deleteName(User user){
        //根据对象不为null的属性充当where条件
        userMapper.delete(new QueryWrapper<>(user));

    }

    public void deleteUS(User user){

        userMapper.delete(new QueryWrapper<>(user));
    }

    /*根据ID删除数据
    * url:http://localhost:8090/user/"+id*/

    public void deleteUserById(Integer id){
        userMapper.deleteById(id);

    }

    public void saveUser(User user){
        userMapper.insert(user);
    }

    public void saveUser2(User user){
        userMapper.insert(user);
    }


    public void updateUser(User user){

        userMapper.updateById(user);
    }




}
